package eu.telecom_bretagne.RECRUT.demo;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import eu.telecom_bretagne.RECRUT.data.model.Candidature;
import eu.telecom_bretagne.RECRUT.service.IServiceCandidature;

public class AppelServiceCandidature {

	public static void main(String[] args) {
		
		test_listeCandidatures();
		
		test_lireCandidature();
		
		test_supprimerCandidature(1);		
		test_listeCandidatures();
		
	}

	public static IServiceCandidature getServiceCandidature() {
		
		InitialContext ctx;
		IServiceCandidature serviceCandidature = null;
		try {
			
			ctx = new InitialContext();
			serviceCandidature = (IServiceCandidature) ctx.lookup(IServiceCandidature.JNDI_NAME);
		} 
		catch (NamingException e) {
			
			// Unable to retrieve the context or the service
			e.printStackTrace();
			System.exit(-1);
		}
		return serviceCandidature;
	}

	public static void test_listeCandidatures() {
		for (Candidature candidature : getServiceCandidature().listeCandidatures()) {
			System.out.println("Candidature id:" + candidature.getId() + " nom:"
					+ candidature.getNomCandidature());
		}
	}
	
	public static void test_lireCandidature() {

		Candidature candidature = getServiceCandidature().lireCandidature(1);
		System.out.println("Candidature id=1 nom:" + candidature.getNomCandidature());
	}
	
	public static void test_supprimerCandidature (int id) {
		
		getServiceCandidature().supprimerCandidature(id);
	}
}
